package com.itheima.controller;

import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.pojo.Student;
import com.itheima.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:
 * @Author: Hank
 * @Date: 2025/3/5 15:30
 */
@Slf4j
@RestController
@RequestMapping("/students")

public class StudentController {
    @Autowired
    private StudentService studentService;
    @GetMapping
    public Result page (String name,
                        String degree,
                        String clazzId,
                        @RequestParam(defaultValue = "1") Integer page,
                        @RequestParam(defaultValue = "10")Integer pageSize){
        PageResult pageResult = studentService.page(name,degree,clazzId,page,pageSize);
        return Result.success(pageResult);

    }
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids){
        studentService.delete(ids);
        return Result.success();
    }
    @PostMapping
    public Result add(@RequestBody Student student){
        studentService.add(student);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getId(@PathVariable Integer id){
        Student student = studentService.getById(id);
        return Result.success(student);
    }
    @PutMapping
    public Result update(@RequestBody Student student){
        studentService.update(student);
        return Result.success();
    }
    @PutMapping("/violation/{id}/{score}")
    public Result violation(@RequestBody Integer id , @RequestBody Integer score){
        studentService.violation(id,score);
        return Result.success();
    }
}
